/* $RCSFile: DisposableBaseType.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/ADNCRM.ExternalResourceProvider/DisposableBaseType.cs $
 * $log$
 * Revision 6 2010/08/06 19:56:30  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;

namespace ADNCRM.CustomResourceProviders
{
   	#region Base TraceSwitch classe that define some usefull properties
	public class ADNTraceSwitchR : TraceSwitch
	{
        public ADNTraceSwitchR()
            : base("DefaultTraceR","Resource Base Trace Switch")
        { }
        public ADNTraceSwitchR(string nm, string des)
            : base(nm, des)
        { }
        public string Info{ get{ return string.Format("{0}-{1}",DisplayName,Level);}}
	}
	#endregion Base TraceSwitch classe that define some usefull properties
	#region TraceSwitch for All Resource provider access
	public class ResourceTraceSwitch
	{
		static public ADNTraceSwitchR	Sw	=	new ADNTraceSwitchR("ResourceTrace","Trace Switch for all Resource access");
	}
	#endregion TraceSwitch for All Resource provider access

	public class DisposableBaseType: IDisposable
    {
        private bool m_Disposed;
        protected bool Disposed
        {
           get
           {
                lock(this)
                {
                    return m_Disposed;
                }
            }
        }

    #region IDisposable Members

        public void Dispose()
        {
            lock (this)
            {
                if (m_Disposed == false)
                {
                    Cleanup();
                    m_Disposed = true;

                    GC.SuppressFinalize(this);
                }
            }
        }

        #endregion

        protected virtual void Cleanup()
        {
            // override to provide cleanup
        } 

        ~DisposableBaseType()   
        {
            Cleanup();
        } 

    }

}
